﻿CREATE PROCEDURE [admin].[s_Mail_System]
	@Subject varchar(512),
	@Body nvarchar(max) = '',
	@Query varchar(max) = '',
	@Recipients varchar(max) = NULL--'Sql Server<help@turbodecision.com>'
AS
DECLARE @DB sysname SET @DB = DB_Name()
SET @Recipients = ISNULL(NULLIF(@Recipients,''),dbo.Registry_EMail_Alert())
DECLARE @ProfileName sysname SET @ProfileName = dbo.Registry_EMailProfile()

EXEC msdb.dbo.sp_send_dbmail
	@profile_name = @ProfileName,--'SysMail',
	@recipients = @Recipients,--'help@afchome.net',
	@subject = @Subject,
	@body = @Body,
	@query = @Query,
@execute_query_database = @DB,
@exclude_query_output = 1
